package com.inspector.app.ui.chat.model;


import android.view.View;

import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.example.commen.net.easyHttp.EasyHttpManager;
import com.example.commen.net.easyHttp.model.HttpData;
import com.hjq.http.listener.HttpCallback;
import com.inspector.app.ui.chat.entity.HistoryMessageEntity;

import java.util.List;

import okhttp3.Call;

public class ActivityTaskChatModel extends ViewModel {
    private MutableLiveData<List<HistoryMessageEntity>> chatBeanList = new MutableLiveData<>();


    public LiveData<List<HistoryMessageEntity>> getHistoryList() {
        return chatBeanList;
    }


    public void getHistoryMessage(LifecycleOwner lifecycleOwner, String taskId) {
        EasyHttpManager.get().get(lifecycleOwner, "/api/v1/cooperationTask/historyMessage?taskId=" + taskId, new HttpCallback<HttpData<List<HistoryMessageEntity>>>() {
            @Override
            public void onSucceed(HttpData<List<HistoryMessageEntity>> result) {
                if (200 == result.getCode()) {
                    List<HistoryMessageEntity> data = result.getData();
                    chatBeanList.postValue(data);
                }
            }

            @Override
            public void onFail(Exception e) {
                chatBeanList.postValue(null);
            }

        });

    }

    public void getRevocationMessage(LifecycleOwner lifecycleOwner, long msgId, HttpCallback<HttpData<String>> callback) {
        EasyHttpManager.get().get(lifecycleOwner, "/api/v1/cooperationTask/revocation?msgId=" + msgId, callback);
    }

}
